clear
set more off

global exper need4
global educ needbd_plus

global dto "change_openings_per_emp"
global initial "initialneed"
global level2000 "avgageexp"
global covars    "initialneed change_openings_per_emp avgageexp"
global stdcovars "stdinitialneed stdavgageexp stdchange_openings_per_emp"

global occfe "i.occsoc_num"
global stfe "i.statefip"
global timefe "b2012.year"

global styearfe "i.styear"
global occyearfe "i.occyear"

global restric "if minto>15 "

global flow "\parbox[c]{1.8cm}{\centering "
global lte "$\leq$"
global gte "$\geq$"

global weight "[w=occshare_state]"




use BGT_2007_2010_2012_withvars_021716_mechanisms.dta
sort statefip year
ren statefip fips
merge m:1 fips year using status3.dta, keep(match) nogen
ren fips statefip
replace percent=percent/100
tempfile a
save `a', replace

keep statefip vet_bplf1yr vet_stlf1yr year
duplicates drop
keep if year==2007
drop year
egen totalvet = sum(vet_stlf1yr)
egen totalvet_bp=sum(vet_bplf1yr)
g vetratio = vet_stlf1yr/totalvet
g vetratio_bp=vet_bplf1yr/totalvet_bp
keep statefip vetratio*
sort statefip
merge 1:m statefip using `a', nogen keep(match)

eststo clear
tsset


g nat_vet_change = ln(predicted_total/L2.predicted_total)
replace nat_vet_change=ln(predicted_total/L3.predicted_total) if nat_vet_change==.

g log_vet_var=     nat_vet_change*vetshare_vsoe* vetratio   * (1-percent)
g log_vet_var_bp = nat_vet_change*vetshare_vsoe* vetratio_bp *(1-percent) 

ren ldvet_vsoe ldvet_vsoe_old
g lfpop=vet_stpopsf*(1-percent)
g ldvet_vsoe = ln(lfpop/L2.lfpop)*vetshare_vsoe
replace ldvet_vsoe= ln(lfpop/L3.lfpop)*vetshare_vsoe if ldvet_vsoe==.



summ dvet_supdem_bgt_bp,d
replace dvet_supdem_bgt_bp=. if dvet_supdem_bgt_bp>r(p95) | dvet_supdem_bgt_bp<r(p5)


//summ dBGTsupdemrate,d
//replace dBGTsupdemrate=. if dBGTsupdemrate>r(p95) | dBGTsupdemrate<r(p5)


			capture drop avgageexp
			gen avgageexp=bdshare2000
			capture drop initialneed
			gen initialneed=initial_needbd_plus07
			capture drop dubdage
			gen dubdage=dubd
		
			eststo: reghdfe dneedbd_plus ldvet_vsoe   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 ldvet_vsoe using vetreplication_participation2, replace 
			
			
			eststo: reghdfe dneedbd_plus ldvet_vsoe   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 ldvet_vsoe using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus log_vet_var   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 log_vet_var using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus log_vet_var   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 log_vet_var using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus log_vet_var_bp   $covars i.year $weight $restric , a(occsoc_num ) vce(cluster statefip)
			outreg2 log_vet_var_bp using vetreplication_participation2, append 
			
				
			eststo: reghdfe dneedbd_plus log_vet_var_bp   $covars i.year $weight $restric , a(occsoc_num statefip ) vce(cluster statefip)
			outreg2 log_vet_var_bp using vetreplication_participation2, append 
						
			
			eststo: reghdfe dneedbd_plus dvet_supdem_bgt_bp   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 dvet_supdem_bgt_bp using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus dvet_supdem_bgt_bp   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 dvet_supdem_bgt_bp using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus   $covars i.year (dBGTsupdemrate=dvet_supdem_bgt_bp)  $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 dBGTsupdemrate using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneedbd_plus   $covars i.year  (dBGTsupdemrate=dvet_supdem_bgt_bp)  $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 dBGTsupdemrate using vetreplication_participation2, append 
			
		
		
		
		
		***********************
		
		capture drop avgageexp
		gen avgageexp=avgage2000
		capture drop initialneed
		gen initialneed=initial_need407
		
		
			eststo: reghdfe dneed4 ldvet_vsoe   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 ldvet_vsoe using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4 ldvet_vsoe   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 ldvet_vsoe using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4 log_vet_var   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 log_vet_var using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4 log_vet_var   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 log_vet_var using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4 log_vet_var_bp   $covars i.year $weight $restric , a(occsoc_num ) vce(cluster statefip)
			outreg2 log_vet_var_bp using vetreplication_participation2, append 
			
				
			eststo: reghdfe dneed4 log_vet_var_bp   $covars i.year $weight $restric , a(occsoc_num statefip ) vce(cluster statefip)
			outreg2 log_vet_var_bp using vetreplication_participation2, append 
			
			
			
			eststo: reghdfe dneed4 dvet_supdem_bgt_bp   $covars i.year $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 dvet_supdem_bgt_bp using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4 dvet_supdem_bgt_bp   $covars i.year $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 dvet_supdem_bgt_bp using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4   $covars i.year (dBGTsupdemrate=dvet_supdem_bgt_bp)  $weight $restric , a(occsoc_num) vce(cluster statefip)
			outreg2 dBGTsupdemrate using vetreplication_participation2, append 
			
			
			eststo: reghdfe dneed4   $covars i.year  (dBGTsupdemrate=dvet_supdem_bgt_bp)  $weight $restric , a(occsoc_num statefip) vce(cluster statefip)
			outreg2 dBGTsupdemrate using vetreplication_participation2, append  excel
			
			
			
			